﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Collections;
using FluentAssertions;
using FluentAssertions.Common;
namespace Wicresot.CoreTests
{


    /// <summary>
    ///这是 CollectionExtensionTest 的测试类，旨在
    ///包含所有 CollectionExtensionTest 单元测试
    ///</summary>
    [TestClass()]
    public class CollectionExtensionTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion



        [TestMethod()]
        public void AddOrUpdateTest()
        {

            Func<int, string, string> updateValueFactory = (i, o) => " _ " + i + o;
            Dictionary<int, string> dictionary = new Dictionary<int, string>();
            var a = dictionary.AddOrUpdate(3, "addvalue", updateValueFactory);
            Console.WriteLine(a);
            a = dictionary.AddOrUpdate(3, "addvalue", updateValueFactory);
            Console.WriteLine(a);
            a = dictionary.AddOrUpdate(3, "addvalue", updateValueFactory);
            Console.WriteLine(a);
            dictionary = new Dictionary<int, string>();
            a = dictionary.AddOrUpdate(3, "addvalue", updateValueFactory);
            Console.WriteLine(a);
            a = dictionary.AddOrUpdate(3, "addvalue", updateValueFactory);
            Console.WriteLine(a);
            a = dictionary.AddOrUpdate(3, "addvalue", updateValueFactory);
            Console.WriteLine(a);
        }



        [TestMethod()]
        public void AddOrUpdateTest1()
        {
            Dictionary<int, string> dictionary = new Dictionary<int, string>();
            int key = default(int);  
            Func<int, string> addValueFactory = i => i + "";
            Func<int, string, string> updateValueFactory = (i, o) => " _ " + i + o;

            var v = dictionary.AddOrUpdate(key, addValueFactory, updateValueFactory);
            Console.WriteLine(v);
            v = dictionary.AddOrUpdate(key, addValueFactory, updateValueFactory);
            Console.WriteLine(v);
            v = dictionary.AddOrUpdate(key, addValueFactory, updateValueFactory);
            Console.WriteLine(v);

        }

        [TestMethod()]
        public void GetOrAddTest()
        {
            Dictionary<int, string> dictionary = new Dictionary<int, string>(); 
            int key = default(int); 
            string value = "zzzxxxddd";
            string actual;
            actual = dictionary.GetOrAdd(key, value);
            Console.WriteLine(actual);
            actual = dictionary.GetOrAdd(key, value);
            Console.WriteLine(actual);
            actual = dictionary.GetOrAdd(key, value);
            Console.WriteLine(actual);
            actual = dictionary.GetOrAdd(key, value);
            Console.WriteLine(actual);
        }



        [TestMethod()]
        public void GetOrAddTest1()
        {
            Dictionary<int, string> dictionary = new Dictionary<int, string>(); 
            int key = default(int); 
            Func<int, string> valueFactory = i => i + " value";
          
            string actual;
            actual = DictionaryExtension.GetOrAdd<int, string>(dictionary, key, valueFactory);
            Console.WriteLine(actual);
            actual = DictionaryExtension.GetOrAdd<int, string>(dictionary, key, valueFactory);
            Console.WriteLine(actual);
            actual = DictionaryExtension.GetOrAdd<int, string>(dictionary, key, valueFactory);
            Console.WriteLine(actual);

            
        }
    }
}
